const BASE_URL = 'http://36.140.133.76:8000/gateway/customer/'
let header = {
	'content-type': 'application/json'
}

// 添加拦截器
const httpInterceptor = {
	//拦截前触发
	invoke(options) {
		if (options.url.includes('login')) {
			options.header = {
				'X-CLIENT': 'CLIENT_APP',
				'X-TOKEN':  ''
			}
		}
	}
}
uni.addInterceptor('request', httpInterceptor)

export const request = (option) => {
	return new Promise((resolve, reject) => {
		header = {
			'X-CLIENT': 'CLIENT_APP',
			'X-TOKEN': uni.getStorageSync('xToken') ? uni.getStorageSync('xToken') : ''
		}
		uni.request({
			url: BASE_URL + option.url,
			method: option.method || 'GET',
			header: header,
			data: option.data,
			responseType: option.responseType ? option.responseType : '',
			success(res) {
				const {
					data,
				} = res
				 if (data.code != 1000) {
					uni.showToast({
						icon: "none",
						duration: 1000,
						title: data.msg
					});
				}
				resolve(data)
			},
			fail(err) {
				const {
					data
				} = err
				reject(data)
			}
		})
	})
}
export {
	BASE_URL
}